package com.taotao.job.core.util;

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.Validate;

import java.util.Random;

/**
 *
 * @author fanbeibei
 * @date 2021/2/22 23:56
 */
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class RadmonUtil {

    public static int nextInt(final int startInclusive, final int endExclusive) {
        Validate.isTrue(endExclusive >= startInclusive,
                "Start value must be smaller or equal to end value.");
        Validate.isTrue(startInclusive >= 0, "Both range values must be non-negative.");

        if (startInclusive == endExclusive) {
            return startInclusive;
        }


        return startInclusive + new Random().nextInt(endExclusive - startInclusive);
    }
}
